/**
 * 
 */
package com.gragra.sequentiaDataGenerator;
import java.util.Arrays;
import com.gragra.sampling.sequentialStructure.ExtensionLevels;
import com.gragra.util.StringToInt;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
/**
 * @author Christoph Teichmann
 * 01.06.2013
 */
public class SimpleSuffixAssigningSegmenter implements Segmentation
{
	/**
	 * 
	 */
	private final int length;
	/**
	 * @param length
	 * @param seg
	 */
	public SimpleSuffixAssigningSegmenter(int length, Segmentation seg)
	{
		super();
		this.length = length;
		this.seg = seg;
	}
	/**
	 * the wrapped segmentation tool
	 */
	private final Segmentation seg;
	/* (non-Javadoc)
	 * @see com.gragra.sequentiaDataGenerator.Segmentation#segment(java.lang.String)
	 */
	@Override
	public ObjectArrayList<String[]> segment(String s)
	{
		ObjectArrayList<String[]> co = seg.segment(s);
		for(int i=0;i<co.size();++i)
		{
			String[] base = co.get(i);
			int l = base.length;
			base = Arrays.copyOf(base, l+2);
			base[l] = ExtensionLevels.SimpleSuffixLevel.name();
			base[l+1] = getSuffixNumber(base[0]);
			base[0] = base[0].toLowerCase();
			co.set(i, base);
		}
		return co;
	}
	/**
	 * 
	 * @param string
	 * @return
	 */
	private String getSuffixNumber(String string)
	{
		int len = string.length();
		if(len <= this.length)
		{return Integer.toString(StringToInt.ensure(""));}
		return Integer.toString(StringToInt.ensure(string.substring(len-this.length,len)));
	}
}